home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / WANDR401.ZIP / sources / solu-io.c < prev    next >
C/C++ Source or Header  |  1997-08-24  |  2KB  |  92 lines

  1. /*               solu-io.c                      */
  2.  
  3. /*     Functions for recording the solution  */
  4.  
  5.  
  6. #include "wand_head.h"
  7.  
  8. extern int debug_disp;
  9. extern char *edit_screen;
  10. extern char lscreen[NOOFROWS][ROWLEN+1];
  11. extern char *edit_memory;
  12. extern char *memory_end;
  13. extern char screen_name[61];
  14. extern char *screenpath;
  15.  
  16.  
  17.  
  18.  
  19. /* save and restore edit memory data */
  20. edit_save(num)
  21. int num;
  22. {
  23.     char file[90];
  24.     int i = 0, fd;
  25.     char *c;
  26.  
  27. if (num>0)
  28.   sprintf(file,"%s/solu/path.%d",screenpath,num);
  29. else
  30.   save_soln_file_name(file);
  31.  
  32. if ((fd = open(file,O_WRONLY|O_CREAT|O_TRUNC,0644)) == -1)
  33.        alert_message("File cannot be opened for writing.");
  34.     else {
  35. /*
  36.     i = write(fd, edit_memory, (int)(memory_end - edit_memory));
  37. */
  38.         for (c=edit_memory;c<memory_end;c++)
  39.           if(*c== 'j' || *c == 'k' || *c == 'l' || *c == 'h'
  40.             || *c == ')' || *c == ' ')   write(fd,c,1);
  41.    
  42.     // if (i < 0) alert_message("Write error on file.");
  43.         close(fd);
  44.     }
  45. }
  46.  
  47. int edit_restore(num)
  48. int num;
  49. {
  50.     char file[90];
  51.     int i = 0, fd;
  52.  
  53. if (num>0)
  54.   sprintf(file,"%s/solu/path.%d",screenpath,num);
  55. else
  56.   load_soln_file_name(file);
  57. if ((fd = open(file,O_RDONLY)) == -1)
  58.         {
  59.         if(num<0)
  60.       alert_message("File cannot be opened for reading.");
  61.         else
  62.           alert_message("No solution file available yet.");
  63.         return -1;
  64.         }
  65.     else {
  66.         for (i=0;i<EMSIZE;i++) edit_memory[i]=0;
  67.     i = read(fd, edit_memory, EMSIZE);
  68.     if (i < 0) alert_message("Read error on file.");
  69.     if (i == 0) alert_message("File empty.");
  70.     if (i > 0) {
  71.         sprintf(file,"Read in %d moves.",i);
  72.         notify_message(file);
  73.             edit_memory[i] = ')';
  74.         memory_end = edit_memory + i;
  75.     }
  76.         close(fd);
  77.     }
  78. return 0;
  79. }
  80.  
  81. int size_of_path_file(num)
  82. int num;
  83. {
  84. long size;
  85. char file[90];
  86. sprintf(file,"%s/solu/path.%d",screenpath,num);
  87. size = file_size(file);
  88. return size;
  89. }
  90.  
  91.  
  92.